<?php
class  Admin_Model_DbTable_CategoryTaxonomy  extends  Kieumau_Db_Common
{
	
	public function init(){
		
		parent::init();
		$this->_name = 'category_taxonomy';
		$this->fieldsPrimary = array('');
		$this->fieldsLanguage = array('');
			
	}
	
	
	public function insertData($id, $taxonomyId){
		try{
			$data = array('category_id'=>$id, 'taxonomy_id'=>$taxonomyId);
			Kieumau_Db_Common::insertData($this->_name, $data);
		}catch(Exception $ex){
			return -1;
		}
	}
	
	
	// @author: Michael.Tran
	// $date: 07/24/2012
	// @function: updateTable
	// @return: id row of table
	public function updateTable($categoryId, $taxonomyId){
		try{
				//Delete the old one
				$this->_db->delete($this->_name,'category_id = '.$categoryId);
				
					if(!empty($taxonomyId)){
					$data = array('category_id'=>$categoryId, 'taxonomy_id'=>$taxonomyId);
					$this->_db->insert($this->_name, $data);
				}
		}catch(Exception $ex){
			return -1;
		}
	}
	
	public function getCategory($taxonomyId, $languageId){
		try {
			$sql = 'SELECT a.category_id, b.name 
					FROM  '.$this->_name.' a
					LEFT JOIN category_language b
					ON a.category_id = b.category_id
					WHERE  a.taxonomy_id = ?
					AND b.lang_id = ?
					';
			$result = $this->_db->fetchAll($sql, array($taxonomyId,$languageId));
			
			/* ================== DEBUG PART 1 
			echo "sql la : $sql";
			echo "<br /> taxonomy_id: $taxonomyId = languageCode: $languageId";
			/**/
			
			return $result;
    	} catch ( Exception $ex ) {
    		echo $ex->getMessage ();
    	}
	}
	
// 	public function activateNews($id){
// 		try {
// 			$sql = "SELECT status FROM news WHERE id = ".(int)$id;
// 			$status = $this->_db->fetchAll($sql);
// 			$status = !$status[0]['status'];
// 			$this->_db->update($this->_name,array('status'=>$status), 'id = '.(int)$id);
//     	} catch ( Exception $ex ) {
//     		echo $ex->getMessage ();
//     	}
// 	}
}
